package com.smart.campus.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.ExamAnswer;
import com.smart.campus.school.service.IExamAnswerService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 试题答案Controller
 * 
 * @author Zhihe.Li
 * @date 2020-05-20
 */
@Controller
@RequestMapping("/school/answer")
public class ExamAnswerController extends BaseController
{
    private String prefix = "school/answer";

    @Autowired
    private IExamAnswerService examAnswerService;

    @RequiresPermissions("school:answer:view")
    @GetMapping()
    public String answer()
    {
        return prefix + "/answer";
    }

    /**
     * 查询试题答案列表
     */
    @RequiresPermissions("school:answer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamAnswer examAnswer)
    {
        startPage();
        List<ExamAnswer> list = examAnswerService.selectExamAnswerList(examAnswer);
        return getDataTable(list);
    }

    /**
     * 导出试题答案列表
     */
    @RequiresPermissions("school:answer:export")
    @Log(title = "试题答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamAnswer examAnswer)
    {
        List<ExamAnswer> list = examAnswerService.selectExamAnswerList(examAnswer);
        ExcelUtil<ExamAnswer> util = new ExcelUtil<ExamAnswer>(ExamAnswer.class);
        return util.exportExcel(list, "answer");
    }

    /**
     * 新增试题答案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试题答案
     */
    @RequiresPermissions("school:answer:add")
    @Log(title = "试题答案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamAnswer examAnswer)
    {
        return toAjax(examAnswerService.insertExamAnswer(examAnswer));
    }

    /**
     * 修改试题答案
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExamAnswer examAnswer = examAnswerService.selectExamAnswerById(id);
        mmap.put("examAnswer", examAnswer);
        return prefix + "/edit";
    }

    /**
     * 修改保存试题答案
     */
    @RequiresPermissions("school:answer:edit")
    @Log(title = "试题答案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamAnswer examAnswer)
    {
        return toAjax(examAnswerService.updateExamAnswer(examAnswer));
    }

    /**
     * 删除试题答案
     */
    @RequiresPermissions("school:answer:remove")
    @Log(title = "试题答案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examAnswerService.deleteExamAnswerByIds(ids));
    }
}
